---
export const prerender = false;
import BaseLayout from "@/layouts/BaseLayout.astro";
import {getBlogById} from "@/service/BlogService";
import {actions} from 'astro:actions';
const result = Astro.getActionResult(actions.blog_edit);
const {searchParams} = new URL(Astro.request.url);
const id = searchParams.get("id")
let blog = null;
if (id) {
    blog = await getBlogById(parseInt(id))
}
---
<BaseLayout>
    <div class="container mx-auto">
        {result && !result.error &&
                <div class="bg-primary text-white p-4 rounded mb-6"> 提交成功</div>}
        {result && result.error &&
                <div class="bg-red-600 text-white p-4 rounded mb-6"> 提交失败</div>}
        <form method="post" action={actions.blog_edit} class="mt-6">
            <h3 class="mb-6">博文编辑</h3>
            <input type="hidden" name="id" value={blog?.id}/>
            <input type="hidden" name="author" value={blog?.author || 'tang.yl'}/>
            <input type="hidden" name="createTime" value={blog?.createTime.toISOString() || null}/>
            <label class="">
                <input name="title" value={blog?.title} class="form-input w-full rounded mb-4"/>
            </label>
            <label>
                <input name="summary" value={blog?.summary} class="form-input w-full rounded mb-4"/>
            </label>
            <label>
                <input name="image" value={blog?.image} class="form-input w-full rounded mb-4"/>
            </label>
            <label>
                <textarea name="content" class="form-textarea w-full rounded mb-4" rows="7">{blog?.content}</textarea>
            </label>
            <button type="submit" class="btn btn-primary">提交</button>
        </form>

    </div>

</BaseLayout>